//
//  XMMessageCell.m
//  XMJJ_zml
//
//  Created by apple on 2025/5/12.
//

#import "XMMessageCell.h"

@interface XMMessageCell ()

@property (nonatomic, strong) UIImageView *avatarImgView;
@property (nonatomic, strong) UILabel *nameLabel;
@property (nonatomic, strong) UILabel *infoLabel;
@property (nonatomic, strong) UILabel *dateLabel;

@end

@implementation XMMessageCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self creatUI];
    }
    return self;
}

- (void)creatUI {
    [self addSubview:self.avatarImgView];
    [self addSubview:self.nameLabel];
    [self addSubview:self.infoLabel];
    [self addSubview:self.dateLabel];
}

- (void)setContentWithMessageModel:(XMMessageModel *)messageMoel {
//    _avatarImgView.image = [UIImage imageWithColor:kColorHEX(0x00ffff)];
    [_avatarImgView sd_setImageWithURL:[NSURL URLWithString:messageMoel.avatar] placeholderImage:ImageNamed(@"mine_avatar_icon")];
    _nameLabel.text = messageMoel.username;//@"刘安迪";
//    _infoLabel.text = @"项目有合作机会吗";
    NSDate *date = [NSDate dateWithTimeIntervalSince1970:[messageMoel.msgTime integerValue]/1000];
    if ([[[NSDate date] dateStringWithFormat:@"yyyy-MM-dd"] isEqualToString:[date dateStringWithFormat:@"yyyy-MM-dd"]]) {
        _dateLabel.text = [date dateStringWithFormat:@"hh:mm"];
    }
    else {
        _dateLabel.text = [date dateStringWithFormat:@"MM月dd日"];
    }
}

#pragma mark - Init

- (UIImageView *)avatarImgView {
    if (!_avatarImgView) {
        _avatarImgView = [[UIImageView alloc] initWithFrame:CGRectMake(KScaleWidth(KScaleWidth(16.0)), (KScaleWidth(77.0) - KScaleWidth(46.0))/2, KScaleWidth(46.0), KScaleWidth(46.0))];
        [_avatarImgView setCornerRadius:_avatarImgView.height/2];
        _avatarImgView.image = ImageNamed(@"mine_avatar_icon");
    }
    return _avatarImgView;
}

- (UILabel *)nameLabel {
    if (!_nameLabel) {
        _nameLabel = [[UILabel alloc] initWithFrame:CGRectMake(KScaleWidth(75.0), KScaleWidth(15.0), kScreenWidth - KScaleWidth(75.0) - KScaleWidth(60.0), KScaleWidth(21.0)) font:KBoldFontSize(15.0) textColor:kColorHEX(0x333333)];
    }
    return _nameLabel;
}

- (UILabel *)infoLabel {
    if (!_infoLabel) {
        _infoLabel = [[UILabel alloc] initWithFrame:CGRectMake(self.nameLabel.x, _nameLabel.maxY, _nameLabel.width, KScaleWidth(20.0)) font:KFontSize(14.0) textColor:kColorHEX(0x999999)];
    }
    return _infoLabel;
}

- (UILabel *)dateLabel {
    if (!_dateLabel) {
        _dateLabel = [[UILabel alloc] initWithFrame:CGRectMake(kScreenWidth - KScaleWidth(15.0) - KScaleWidth(70.0), KScaleWidth(12.0), KScaleWidth(70.0), KScaleWidth(30.0)) font:KFontSize(14.0) textColor:kColorHEX(0x999999) textAlignment:NSTextAlignmentRight];
    }
    return _dateLabel;
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
